package cn.bytecollege.user.controller;

import cn.bytecollege.admin.service.ProductService;
import cn.bytecollege.common.entity.Page;
import cn.bytecollege.common.entity.Product;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ProductListIndexController",value = "/index")
public class ProductListIndexController extends HttpServlet {
    private ProductService productService=null;
    public ProductListIndexController (){
        productService=new ProductService();
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String index = request.getParameter("index");
        int pageIndex = (index==null)?1:Integer.parseInt(index);
        String size = request.getParameter("size");
        int pageSize = (size==null)?10:Integer.parseInt(size);
        Page<Product> page = productService.findListByPage(pageIndex,pageSize);
        request.setAttribute("page",page);
        request.getRequestDispatcher("/index.jsp").forward(request,response);
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       doPost(request, response);
    }
}
